
#include <cassert>
#include <iostream>
#include <mpi.h>
#include <vector>
using namespace std;

int main(int argc, char **argv) {
  int my_rank, num_proc;
  MPI_Init(&argc, &argv);
  MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  MPI_Comm_size(MPI_COMM_WORLD, &num_proc);
  vector<int> all_rank;
  if (my_rank == 3) {
    all_rank.resize(num_proc);
  }
  // 自己的也会填进去
  MPI_Gather(&my_rank, 1, MPI_INT, all_rank.data(), 1, MPI_INT, 3,
             MPI_COMM_WORLD);

  if (my_rank == 3) {
    for (int i = 0; i < num_proc; ++i)
      cout << all_rank[i] << "  ";
    cout << endl;
  }

  MPI_Finalize();

  return 0;
}